<?php


abstract class BasesfMedicament extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $categorie_id;


	
	protected $libelle;


	
	protected $qte_en_stock;


	
	protected $seuil_critique;


	
	protected $seuil_minimal;


	
	protected $seuil_optimimum;


	
	protected $seuil_maximal;


	
	protected $code_barre;

	
	protected $asfCategorieMedicament;

	
	protected $collsfTraitementMedicaments;

	
	protected $lastsfTraitementMedicamentCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getCategorieId()
	{

		return $this->categorie_id;
	}

	
	public function getLibelle()
	{

		return $this->libelle;
	}

	
	public function getQteEnStock()
	{

		return $this->qte_en_stock;
	}

	
	public function getSeuilCritique()
	{

		return $this->seuil_critique;
	}

	
	public function getSeuilMinimal()
	{

		return $this->seuil_minimal;
	}

	
	public function getSeuilOptimimum()
	{

		return $this->seuil_optimimum;
	}

	
	public function getSeuilMaximal()
	{

		return $this->seuil_maximal;
	}

	
	public function getCodeBarre()
	{

		return $this->code_barre;
	}

	
	public function setId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = sfMedicamentPeer::ID;
		}

	} 
	
	public function setCategorieId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->categorie_id !== $v) {
			$this->categorie_id = $v;
			$this->modifiedColumns[] = sfMedicamentPeer::CATEGORIE_ID;
		}

		if ($this->asfCategorieMedicament !== null && $this->asfCategorieMedicament->getId() !== $v) {
			$this->asfCategorieMedicament = null;
		}

	} 
	
	public function setLibelle($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->libelle !== $v) {
			$this->libelle = $v;
			$this->modifiedColumns[] = sfMedicamentPeer::LIBELLE;
		}

	} 
	
	public function setQteEnStock($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->qte_en_stock !== $v) {
			$this->qte_en_stock = $v;
			$this->modifiedColumns[] = sfMedicamentPeer::QTE_EN_STOCK;
		}

	} 
	
	public function setSeuilCritique($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->seuil_critique !== $v) {
			$this->seuil_critique = $v;
			$this->modifiedColumns[] = sfMedicamentPeer::SEUIL_CRITIQUE;
		}

	} 
	
	public function setSeuilMinimal($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->seuil_minimal !== $v) {
			$this->seuil_minimal = $v;
			$this->modifiedColumns[] = sfMedicamentPeer::SEUIL_MINIMAL;
		}

	} 
	
	public function setSeuilOptimimum($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->seuil_optimimum !== $v) {
			$this->seuil_optimimum = $v;
			$this->modifiedColumns[] = sfMedicamentPeer::SEUIL_OPTIMIMUM;
		}

	} 
	
	public function setSeuilMaximal($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->seuil_maximal !== $v) {
			$this->seuil_maximal = $v;
			$this->modifiedColumns[] = sfMedicamentPeer::SEUIL_MAXIMAL;
		}

	} 
	
	public function setCodeBarre($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->code_barre !== $v) {
			$this->code_barre = $v;
			$this->modifiedColumns[] = sfMedicamentPeer::CODE_BARRE;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->categorie_id = $rs->getInt($startcol + 1);

			$this->libelle = $rs->getString($startcol + 2);

			$this->qte_en_stock = $rs->getInt($startcol + 3);

			$this->seuil_critique = $rs->getInt($startcol + 4);

			$this->seuil_minimal = $rs->getInt($startcol + 5);

			$this->seuil_optimimum = $rs->getInt($startcol + 6);

			$this->seuil_maximal = $rs->getInt($startcol + 7);

			$this->code_barre = $rs->getString($startcol + 8);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 9; 
		} catch (Exception $e) {
			throw new PropelException("Error populating sfMedicament object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(sfMedicamentPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			sfMedicamentPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(sfMedicamentPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->asfCategorieMedicament !== null) {
				if ($this->asfCategorieMedicament->isModified()) {
					$affectedRows += $this->asfCategorieMedicament->save($con);
				}
				$this->setsfCategorieMedicament($this->asfCategorieMedicament);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = sfMedicamentPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += sfMedicamentPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collsfTraitementMedicaments !== null) {
				foreach($this->collsfTraitementMedicaments as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->asfCategorieMedicament !== null) {
				if (!$this->asfCategorieMedicament->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->asfCategorieMedicament->getValidationFailures());
				}
			}


			if (($retval = sfMedicamentPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collsfTraitementMedicaments !== null) {
					foreach($this->collsfTraitementMedicaments as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = sfMedicamentPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getCategorieId();
				break;
			case 2:
				return $this->getLibelle();
				break;
			case 3:
				return $this->getQteEnStock();
				break;
			case 4:
				return $this->getSeuilCritique();
				break;
			case 5:
				return $this->getSeuilMinimal();
				break;
			case 6:
				return $this->getSeuilOptimimum();
				break;
			case 7:
				return $this->getSeuilMaximal();
				break;
			case 8:
				return $this->getCodeBarre();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = sfMedicamentPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getCategorieId(),
			$keys[2] => $this->getLibelle(),
			$keys[3] => $this->getQteEnStock(),
			$keys[4] => $this->getSeuilCritique(),
			$keys[5] => $this->getSeuilMinimal(),
			$keys[6] => $this->getSeuilOptimimum(),
			$keys[7] => $this->getSeuilMaximal(),
			$keys[8] => $this->getCodeBarre(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = sfMedicamentPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setCategorieId($value);
				break;
			case 2:
				$this->setLibelle($value);
				break;
			case 3:
				$this->setQteEnStock($value);
				break;
			case 4:
				$this->setSeuilCritique($value);
				break;
			case 5:
				$this->setSeuilMinimal($value);
				break;
			case 6:
				$this->setSeuilOptimimum($value);
				break;
			case 7:
				$this->setSeuilMaximal($value);
				break;
			case 8:
				$this->setCodeBarre($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = sfMedicamentPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setCategorieId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setLibelle($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setQteEnStock($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setSeuilCritique($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setSeuilMinimal($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setSeuilOptimimum($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setSeuilMaximal($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setCodeBarre($arr[$keys[8]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(sfMedicamentPeer::DATABASE_NAME);

		if ($this->isColumnModified(sfMedicamentPeer::ID)) $criteria->add(sfMedicamentPeer::ID, $this->id);
		if ($this->isColumnModified(sfMedicamentPeer::CATEGORIE_ID)) $criteria->add(sfMedicamentPeer::CATEGORIE_ID, $this->categorie_id);
		if ($this->isColumnModified(sfMedicamentPeer::LIBELLE)) $criteria->add(sfMedicamentPeer::LIBELLE, $this->libelle);
		if ($this->isColumnModified(sfMedicamentPeer::QTE_EN_STOCK)) $criteria->add(sfMedicamentPeer::QTE_EN_STOCK, $this->qte_en_stock);
		if ($this->isColumnModified(sfMedicamentPeer::SEUIL_CRITIQUE)) $criteria->add(sfMedicamentPeer::SEUIL_CRITIQUE, $this->seuil_critique);
		if ($this->isColumnModified(sfMedicamentPeer::SEUIL_MINIMAL)) $criteria->add(sfMedicamentPeer::SEUIL_MINIMAL, $this->seuil_minimal);
		if ($this->isColumnModified(sfMedicamentPeer::SEUIL_OPTIMIMUM)) $criteria->add(sfMedicamentPeer::SEUIL_OPTIMIMUM, $this->seuil_optimimum);
		if ($this->isColumnModified(sfMedicamentPeer::SEUIL_MAXIMAL)) $criteria->add(sfMedicamentPeer::SEUIL_MAXIMAL, $this->seuil_maximal);
		if ($this->isColumnModified(sfMedicamentPeer::CODE_BARRE)) $criteria->add(sfMedicamentPeer::CODE_BARRE, $this->code_barre);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(sfMedicamentPeer::DATABASE_NAME);

		$criteria->add(sfMedicamentPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setCategorieId($this->categorie_id);

		$copyObj->setLibelle($this->libelle);

		$copyObj->setQteEnStock($this->qte_en_stock);

		$copyObj->setSeuilCritique($this->seuil_critique);

		$copyObj->setSeuilMinimal($this->seuil_minimal);

		$copyObj->setSeuilOptimimum($this->seuil_optimimum);

		$copyObj->setSeuilMaximal($this->seuil_maximal);

		$copyObj->setCodeBarre($this->code_barre);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getsfTraitementMedicaments() as $relObj) {
				$copyObj->addsfTraitementMedicament($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new sfMedicamentPeer();
		}
		return self::$peer;
	}

	
	public function setsfCategorieMedicament($v)
	{


		if ($v === null) {
			$this->setCategorieId(NULL);
		} else {
			$this->setCategorieId($v->getId());
		}


		$this->asfCategorieMedicament = $v;
	}


	
	public function getsfCategorieMedicament($con = null)
	{
		if ($this->asfCategorieMedicament === null && ($this->categorie_id !== null)) {
						include_once 'lib/model/om/BasesfCategorieMedicamentPeer.php';

			$this->asfCategorieMedicament = sfCategorieMedicamentPeer::retrieveByPK($this->categorie_id, $con);

			
		}
		return $this->asfCategorieMedicament;
	}

	
	public function initsfTraitementMedicaments()
	{
		if ($this->collsfTraitementMedicaments === null) {
			$this->collsfTraitementMedicaments = array();
		}
	}

	
	public function getsfTraitementMedicaments($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BasesfTraitementMedicamentPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collsfTraitementMedicaments === null) {
			if ($this->isNew()) {
			   $this->collsfTraitementMedicaments = array();
			} else {

				$criteria->add(sfTraitementMedicamentPeer::MEDICAMENT_ID, $this->getId());

				sfTraitementMedicamentPeer::addSelectColumns($criteria);
				$this->collsfTraitementMedicaments = sfTraitementMedicamentPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(sfTraitementMedicamentPeer::MEDICAMENT_ID, $this->getId());

				sfTraitementMedicamentPeer::addSelectColumns($criteria);
				if (!isset($this->lastsfTraitementMedicamentCriteria) || !$this->lastsfTraitementMedicamentCriteria->equals($criteria)) {
					$this->collsfTraitementMedicaments = sfTraitementMedicamentPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastsfTraitementMedicamentCriteria = $criteria;
		return $this->collsfTraitementMedicaments;
	}

	
	public function countsfTraitementMedicaments($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BasesfTraitementMedicamentPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(sfTraitementMedicamentPeer::MEDICAMENT_ID, $this->getId());

		return sfTraitementMedicamentPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addsfTraitementMedicament(sfTraitementMedicament $l)
	{
		$this->collsfTraitementMedicaments[] = $l;
		$l->setsfMedicament($this);
	}


	
	public function getsfTraitementMedicamentsJoinsfTraitement($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BasesfTraitementMedicamentPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collsfTraitementMedicaments === null) {
			if ($this->isNew()) {
				$this->collsfTraitementMedicaments = array();
			} else {

				$criteria->add(sfTraitementMedicamentPeer::MEDICAMENT_ID, $this->getId());

				$this->collsfTraitementMedicaments = sfTraitementMedicamentPeer::doSelectJoinsfTraitement($criteria, $con);
			}
		} else {
									
			$criteria->add(sfTraitementMedicamentPeer::MEDICAMENT_ID, $this->getId());

			if (!isset($this->lastsfTraitementMedicamentCriteria) || !$this->lastsfTraitementMedicamentCriteria->equals($criteria)) {
				$this->collsfTraitementMedicaments = sfTraitementMedicamentPeer::doSelectJoinsfTraitement($criteria, $con);
			}
		}
		$this->lastsfTraitementMedicamentCriteria = $criteria;

		return $this->collsfTraitementMedicaments;
	}

} 